package com.example.costumview.activity2;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.costumview.R;

import java.util.ArrayList;
import java.util.List;

public class SlideDeleteRecyActivity extends AppCompatActivity {

    RecyclerView mRecy;

    private List<String> mData;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_slide_delete_recy);

        mRecy=findViewById(R.id.recyclerview);
        mRecy.setLayoutManager(new LinearLayoutManager(this));
        DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL);
        dividerItemDecoration.setDrawable(new ColorDrawable(Color.WHITE));
        mRecy.addItemDecoration(dividerItemDecoration);

        mData=new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            mData.add(""+i);
        }
        mRecy.setAdapter(new DeleteAdapter(mData));
    }

    class DeleteAdapter extends RecyclerView.Adapter<DeleteAdapter.DeleteViewHolder>{

        private List<String> mData;

        public DeleteAdapter(List<String> mData) {
            this.mData = mData;
        }

        @NonNull
        @Override
        public DeleteViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.slide_recycler_item,parent,false);
            return  new DeleteViewHolder(view);
        }

        @Override
        public void onBindViewHolder(@NonNull DeleteViewHolder holder, int position) {
            holder.textView.setText(mData.get(position));
        }

        @Override
        public int getItemCount() {
            return mData.size();
        }

        class DeleteViewHolder extends RecyclerView.ViewHolder{
            TextView textView;
            public DeleteViewHolder(@NonNull View itemView) {
                super(itemView);
                textView=itemView.findViewById(R.id.recyclerview_tv);
            }
        }
    }
}